package com.example.second_home_work

import android.os.Bundle
import android.widget.LinearLayout
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    val expert = ProgramEXpert()
    private var textViewCounter = 1

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        val button = findViewById<android.widget.Button>(R.id.button)
        val spinner = findViewById<android.widget.Spinner>(R.id.spinner)
        val spinnerText = findViewById<android.widget.TextView>(R.id.spinnerText)
        button.setOnClickListener {
            val selectedFeature = spinner.selectedItem.toString()
            spinnerText.text = expert.getLanguage(selectedFeature)
        }
        val button_addtext = findViewById<android.widget.Button>(R.id.buttonAdd)
        val container = findViewById<LinearLayout>(R.id.container)
        button_addtext.setOnClickListener{
            val textView = TextView(this)
            val textTemplate = getString(R.string.TextView)
            textView.text = String.format(textTemplate, textViewCounter)
            textView.layoutParams = LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
            )
            container.addView(textView)
            textViewCounter++
        }
    }
}